<?php
App::uses('AppModel', 'Model');
/**
 * Distancia Model
 *
 * @property Anuncio $Anuncio
 */
class Distancia extends AppModel {
/**
 * Primary key field
 *
 * @var string
 */
	public $primaryKey = 'id_distacias';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'id_distancias' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'anuncio_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'tempo_do_estadio' => array(
			'aPe' => array(
					'rule' => 'validaDistancia',
					'message' => 'Valor não numérico',
				),
		),
		'tipo_de_transporte' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Anuncio' => array(
			'className' => 'Anuncio',
			'foreignKey' => 'anuncio_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	public function validaDistancia ($data) {
		if (is_numeric ($this->data['Distancia']['tempo_do_estadio']))
			return true;
		else
			if ($this->data['Distancia']['tipo_de_transporte'] == 0 && empty($this->data['Distancia']['tempo_do_estadio']))
				return true;
		return false;
	}
	
}
